package gp;

/**
 * This is the base class for all kinds of tree nodes.
 */
abstract class Program implements Cloneable {

	/**
	 * @param level
	 *            the current recursion level when descending a subtree
	 * @return the text representation of the subtree
	 */
	public abstract String toString(int level);

	/**
	 * @return a text description of the node. While toString() prints the value
	 *         of a subtree, getName() returns something like the class name of
	 *         this very node. getName() can be used to preset the choice lists
	 *         for the function and terminal sets.
	 */
	abstract String getName();

	/**
	 * @return a series of blanks proportional to the recursion level
	 * @param level
	 */
	String indent(int level) {
		String s = "";
		for (int i = 0; i < level; i++) {
			s = (s + "  ");
		}
		return s;
	}

	/**
	 * @return the value of the subtree, evaluated at x, i.e. y = f(x)
	 * @param x
	 */
	abstract double eval(double x);

	/**
	 * @return the number of nodes in this subtree
	 */
	abstract int countNodes();

	/**
	 * @return the number of nodes in this subtree satisfying a certain
	 *         condition
	 * @param cond
	 */
	abstract int countNodes(Condition cond);

	/**
	 * @return a deep copy of the subtree
	 */
	protected abstract Object clone();
}